package com.zx.auth.block.modle;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.time.LocalDateTime;


/**
 * <p>
 * description: OAuth2 注册客户端实体类，对应数据库表 oauth2_registered_client，存储已注册的OAuth2客户端信息 <br>
 * create: 2025-04-25 10:46 <br>
 * </p>
 *
 * @author zhou  xun
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "oauth2_registered_client")
public class OAuth2RegisteredClient implements Serializable {

    /* 基础信息字段 */

    /**
     * 主键ID，由应用层生成
     */
    @Id
    @Column(name = "id", length = 100, nullable = false)
    private String id;

    /**
     * 客户端ID，用于OAuth2流程中识别客户端
     */
    @Column(name = "client_id", length = 100, nullable = false)
    private String clientId;

    /**
     * 客户端ID发放时间
     */
    @Column(name = "client_id_issued_at", nullable = false)
    private LocalDateTime clientIdIssuedAt;

    /* 安全相关字段 */

    /**
     * 客户端密钥，可能为空(如PKCE流程)
     */
    @Column(name = "client_secret", length = 200)
    private String clientSecret;

    /**
     * 客户端密钥过期时间，null表示永不过期
     */
    @Column(name = "client_secret_expires_at")
    private LocalDateTime clientSecretExpiresAt;

    /* 客户端描述信息 */

    /**
     * 客户端名称，显示给用户看的名称
     */
    @Column(name = "client_name", length = 200, nullable = false)
    private String clientName;

    /* 认证配置字段 */

    /**
     * 客户端认证方法(client_secret_basic等)，多个方法用逗号分隔
     */
    @Column(name = "client_authentication_methods", length = 1000, nullable = false)
    private String clientAuthenticationMethods;

    /**
     * 支持的授权类型(authorization_code等)，多个类型用逗号分隔
     */
    @Column(name = "authorization_grant_types", length = 1000, nullable = false)
    private String authorizationGrantTypes;

    /* URI配置字段 */

    /**
     * 重定向URI列表，多个URI用逗号分隔
     */
    @Column(name = "redirect_uris", length = 1000)
    private String redirectUris;

    /**
     * 登出后重定向URI列表，多个URI用逗号分隔
     */
    @Column(name = "post_logout_redirect_uris", length = 1000)
    private String postLogoutRedirectUris;

    /* 权限范围字段 */

    /**
     * 支持的scope范围，多个scope用逗号分隔
     */
    @Column(name = "scopes", length = 1000, nullable = false)
    private String scopes;

    /* 配置信息字段 */

    /**
     * 客户端设置(JSON格式)，包含客户端特定的配置
     */
    @Column(name = "client_settings", length = 2000, nullable = false)
    private String clientSettings;

    /**
     * 令牌设置(JSON格式)，包含令牌相关的配置
     */
    @Column(name = "token_settings", length = 2000, nullable = false)
    private String tokenSettings;

    /**
     * 租户ID
     */
    @Column(name = "tenant_id", length = 32, nullable = false)
    private String tenantId;
}